package com.smartstate.IOC.service.impl;

import com.smartstate.IOC.mapper.SecuritySituationMapper;
import com.smartstate.IOC.service.SecuritySituationService;
import com.smartstate.IOC.vo.ConutEquipment;
import com.smartstate.IOC.vo.CountEquipmentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class SecuritySituationServiceImpl implements SecuritySituationService {
    @Resource
    private SecuritySituationMapper situationMapper;

    @Override
    public CountEquipmentVO countEquipmentType() {
        List<ConutEquipment> conutEquipments = situationMapper.countEquipmentType();
        Integer total=0;
        if (conutEquipments.isEmpty()){
            CountEquipmentVO countEquipmentVO = new CountEquipmentVO();
            countEquipmentVO.setTotal(total);
            return countEquipmentVO;
        }else {
            for (ConutEquipment conutEquipment : conutEquipments) {
                Integer amount = conutEquipment.getAmount();
                total=total+amount;
            }
            CountEquipmentVO countEquipmentVO = new CountEquipmentVO();
            countEquipmentVO.setTotal(total);
            countEquipmentVO.setEquipmentList(conutEquipments);
            return countEquipmentVO;
        }
    }
}
